#include <iostream>
using namespace std;

const int N = 10;
int ans[N];
bool a[N];
int n;

void dfs(int t)
{
    for (int i = 1; i <= n; ++i)
        if (!a[i])
        {
            ans[t] = i;
            a[i] = true;
            dfs(t + 1);
            ans[t] = 0;
            a[i] = false;
        }
    if (t == n)
    {
        for (int i = 0; i < n; ++i)
            cout << ans[i] << " ";
        cout << endl;
    }
    return;
}

int main()
{
    cin >> n;
    dfs(0);
    return 0;
}